var prefix = ctx + "admin/param";

$(function() {
	var options = {
		url : prefix + "/page",
		updateUrl: prefix + "/goEditParam",
        removeUrl: prefix + "/{id}",
		sortName : "createTime",
		sortOrder : "desc",
		modalName : "参数",
		columns : [
				{
		            title: "序号",
		            formatter: function (value, row, index) {
		         	    return $.table.serialNumber(index);
		            }
		        },
				{
					field : 'publicName',
					title : '参数名称',
					formatter : function(value, row, index) {
						return $.table.tooltip(value);
					}
				},
				{
					field : 'publicKey',
					title : '参数键名',
					formatter : function(value, row, index) {
						return $.table.tooltip(value);
					}
				},
				{
					field : 'publicValue',
					title : '参数键值'
				},
				{
					field : 'systemFlag',
					title : '参数类型',
					align : 'center',
					formatter : function(value, row, index) {
						return $.table.selectDictLabel(system_datas, value);
					}
				},
				{
					field : 'status',
					title : '参数状态',
					align : 'center',
					formatter : function(value, row, index) {
						return statusTools(row);
					}
				},
				{
					field : 'publicType',
					title : '参数小类',
					align : 'center',
					formatter : function(value, row, index) {
						return $.table.selectDictLabel(type_datas, value);
					}
				},
				{
					field : 'createTime',
					title : '创建时间'
				},
				{
					title : '操作',
					align : 'center',
					formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.publicId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + deleteFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.publicId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
				} ]
	};
	$.table.init(options);
});
        
function statusTools(row) {
	if (row.status == 9) {
		return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\''
				+ row.publicId + '\')"></i> ';
	} else {
		return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\''
				+ row.publicId + '\')"></i> ';
	}
}   

function disable(publicId) {
	$.modal.confirm("确认要停用参数吗？", function() {
		$.operate.post(prefix + "/changeStatus", {
			"publicId" : publicId,
			"status" : 9
		});
	})
}

function enable(publicId) {
	$.modal.confirm("确认要启用参数吗？", function() {
		$.operate.post(prefix + "/changeStatus", {
			"publicId" : publicId,
			"status" : 0
		});
	})
}
